<?php
function Rename_Submenu($Payment_ID, $Payment_New_Name){
	$sql="
          UPDATE payment_types
          SET 
            pt_name=\"$Payment_New_Name\"
          WHERE id=$Payment_ID";
	//print $sql;
	@$sql_result = mysql_query($sql);
	return $sql_result;
}

function Delete_Submenu($Payment_ID){
  	//test, ci podkategoria neobsahuje produkty
    if(is_numeric($Payment_ID) and $Payment_ID>0){
        $result = mysql_query("DELETE FROM payment_types WHERE id=".$Payment_ID);
        $result = $result and mysql_query("DELETE FROM delivery_payment WHERE pt_id =".$Payment_ID);
        return $result;
    }
    else 
        return false;

}

function Insert_Submenu($Delivery_ID, $Payment_Name){
	mysql_query("INSERT INTO payment_types (pt_name) VALUES(\"$Payment_Name\")");
    $Payment_ID = mysql_insert_id();
    if($Payment_ID>0) return mysql_query("INSERT INTO delivery_payment (dt_id, pt_id) VALUES($Delivery_ID, $Payment_ID)");

	return false;
}

function Insert_Topmenu($Payment_Name){
    return mysql_query("INSERT INTO delivery_types  (dt_name) VALUES(\"$Payment_Name\")");
}

function Rename_Topmenu($Delivery_ID, $Delivery_New_Name){
    return mysql_query("
      UPDATE delivery_types
      SET 
        dt_name=\"$Delivery_New_Name\"
      WHERE id=$Delivery_ID");
}

function GetSubmenuInfo($ID, &$Caption){
    if(!is_numeric($ID) and $ID<1) return 0;
    
    @$sql_result=mysql_query("SELECT * FROM payment_types WHERE id=".$ID);
    $sql_result_obj = mysql_fetch_object($sql_result);
            
    $Caption=$sql_result_obj->pt_name;
    
    return $sql_result;
}

function GetTopmenuInfo($ID, &$Caption){
    if(!is_numeric($ID) and $ID<1) return 0;
    
    @$sql_result=mysql_query("SELECT * FROM delivery_types WHERE id=".$ID);
    $sql_result_obj = mysql_fetch_object($sql_result);
            
    $Caption=$sql_result_obj->dt_name;
    
    return $sql_result;
}

function Delete_Topmenu($Delete_Topmenu_ID){
    $result = mysql_query("DELETE FROM payment_types WHERE id = ANY (SELECT pt_id FROM delivery_payment WHERE dt_id=$Delete_Topmenu_ID)");
    $result = $result and mysql_query("DELETE FROM delivery_payment WHERE dt_id = $Delete_Topmenu_ID");
    $result = $result and mysql_query("DELETE FROM delivery_types WHERE id = $Delete_Topmenu_ID");
    return $result;
}

function New_Submenu_Form($ShowAsNewSubCategory,$ActualTCID,$roll_menu){
	if($ShowAsNewSubCategory==$ActualTCID)
            print "
                <table cellpadding=\"0\" cellspacing=\"0\" style=\"border: 0px;\">
                <tr>
                    <td>
                        <form action=\"categorie_creator.php\" method=\"post\">
                            <table cellpadding=\"0\" cellspacing=\"0\" style=\"border: 0px;\">
                            <tr>
                                <td>
                                    <input type=\"hidden\" value=\"NO\" name=\"ShowAsNewSubCategory\" />
                                    <input type=\"hidden\" value=\"".$roll_menu."\" name=\"roll_menu\" />
                                    <input type=\"hidden\" value=\"".$ActualTCID."\" name=\"TC_ID\" />
                                    <input type=\"text\" value=\"".CC_NAZOV."\" name=\"Submenu_Caption\" 
                                        style=\"width:150px;background-color:white;border:1px solid black;\" />
                                </td>
                                <td>
                                    <input type=\"submit\" value=\"".CC_OK."\" style=\"width :50px;border:1px solid black;\"
                                        onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\"
                                        onmouseout= \"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />
                                </td>
                            </tr>
                            </table>
                        </form>
                    </td>
                    <td>
                        <form action=\"categorie_creator.php\" method=\"post\">
                            <input type=\"hidden\" value=\"NO\" name=\"ShowAsNewSubCategory\" />
                            <input type=\"hidden\" value=\"".$roll_menu."\" name=\"roll_menu\" />
                            <input type=\"submit\" value=\"".CC_ZRUSIT."\" style=\"width :50px;border:1px solid black;\"
                                onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\"
                                onmouseout= \"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />
                        </form>
                    </td>
                </tr>
                </table>";
	else
            print "
                <form action=\"categorie_creator.php\" method=\"post\">
                    <input type=\"hidden\" value=\"".$sql_array_SMnu->ID."\" name=\"ID\" />
                    <input type=\"hidden\" value=\"$ActualTCID\" name=\"ShowAsNewSubCategory\" />
                    <input type=\"hidden\" value=\"".$roll_menu."\" name=\"roll_menu\" />
                    <input type=\"submit\" value=\"".CPC_PRIDAT_SPOSOB_PLATBY."\" style=\"width :310px;border:1px solid black;\"
                        onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\"
                        onmouseout= \"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />
                </form>";
}

function Rename_Submenu_Form($ShowAsUpdate,$ActualID,$roll_menu){
	if($ShowAsUpdate==$ActualID){
        $Caption='';
        GetSubmenuInfo($ActualID, $Caption);
		print "
			<table cellpadding=\"0\" cellspacing=\"0\" style=\"border: 0px; font-family: verdana; font-size: 10px;\">
			<tr>
				<td>
					<form action=\"categorie_creator.php\" method=\"post\">
						<table cellpadding=\"0\" cellspacing=\"0\" style=\"border: 0px;width:100%;\">
						<tr style=\"border: 0px; font-family: verdana; font-size: 10px;\">
							<td>
                                <input type=\"hidden\" value=\"NO\" name=\"ShowAsUpdate\" />
                                <input type=\"hidden\" value=\"".$roll_menu."\" name=\"roll_menu\" />
                                <input type=\"hidden\" value=\"".$ActualID."\" name=\"Rename_Submenu_ID\" />
                                <input type=\"text\" value=\"".$Caption."\" name=\"Submenu_New_Caption\"
                                    style=\"width:115px;background-color:white;border:1px solid black;\"
                                />
                            </td>
							<td>
                                <input type=\"submit\" value=\"".CC_OK."\" style=\"width:50px;border:1px solid black;\"
                                    onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\"
                                    onmouseout= \"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />
                            </td>
						</tr>
						</table>
					</form>
				<td>
					<form action=\"categorie_creator.php\" method=\"post\">
                        <input type=\"hidden\" value=\"NO\" name=\"ShowAsUpdate\" />
                        <input type=\"hidden\" value=\"".$roll_menu."\" name=\"roll_menu\" />
                        <input type=\"submit\" value=\"".CC_ZRUSIT."\" style=\"width :50px;border:1px solid black;\"
                            onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\"
                            onmouseout= \"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />
					</form>
				</td>
			</tr>
			</table>";		
        }
	else{
		print "
			<form action=\"categorie_creator.php\" method=\"post\">
                            <input type=\"hidden\" value=\"".$sql_array_SMnu->ID."\" name=\"ID\" />
                            <input type=\"hidden\" value=\"$ActualID\" name=\"ShowAsUpdate\" />
                            <input type=\"hidden\" value=\"".$roll_menu."\" name=\"roll_menu\" />
                            <input type=\"submit\" value=\"".CC_PREMENOVAT."\" style=\"width :310px;border:1px solid black;text-align:center;\"
		        	onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\"
		        	onmouseout= \"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />
			</form>";
        }
}

function Delete_Submenu_Form($ShowAsDelete,$ActualID,$roll_menu){
	if($ShowAsDelete==$ActualID)
		print "
			<table cellpadding=\"0\" cellspacing=\"0\" style=\"border: 0px;\">
			<tr>
				<td>
					<form action=\"categorie_creator.php\" method=\"post\">
						<table cellpadding=\"0\" cellspacing=\"0\" style=\"border: 0px;\">
						<tr>
							<td>
								<font style=\"font-size:10px;font-family:verdana;\"><b>".CC_NAOZAJ_ODSTRANIT."</b></font><br />
							</td>
							<td>
								<input type=\"hidden\" value=\"NO\" name=\"ShowAsDelete\" />
							</td>
							<td>
								<input type=\"hidden\" value=\"".$roll_menu."\" name=\"roll_menu\" />
								<input type=\"hidden\" value=\"".$ActualID."\" name=\"Delete_Submenu_ID\" />
                                                                <input type=\"submit\" value=\"".CC_ANO."\" style=\"width :50px;border:1px solid black;\"
						        	onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\"
						        	onmouseout= \"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />
						    </td>
						</tr>
						</table>
					</form>
				</td>
				<td>
					<form action=\"categorie_creator.php\" method=\"post\">
						<input type=\"hidden\" value=\"NO\" name=\"ShowAsDelete\" />
						<input type=\"hidden\" value=\"".$roll_menu."\" name=\"roll_menu\" />
				    	<input type=\"submit\" value=\"".CC_NIE."\" style=\"width :50px;border:1px solid black;\"
				        	onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\"
				        	onmouseout= \"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />
					</form>
				</td>
			</tr>
		</table>";
	else
		print "
			<form action=\"categorie_creator.php\" method=\"post\">
				<input type=\"hidden\" value=\"".$sql_array_SMnu->ID."\" name=\"ID\" />
				<input type=\"hidden\" value=\"$ActualID\" name=\"ShowAsDelete\" />
				<input type=\"hidden\" value=\"".$roll_menu."\" name=\"roll_menu\" />
		    	<input type=\"submit\" value=\"".CC_ODSTRANIT."\" style=\"width :210px;border:1px solid black;text-align:center;\"
		        	onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\"
		        	onmouseout= \"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />
			</form>";
}

function New_Topmenu_Form($ShowAsNewTopCategory,$roll_menu){
	if($ShowAsNewTopCategory=="YES"){
		print "
                    <table cellpadding=\"0\" cellspacing=\"0\" style=\"border: 0px;\">
                    <tr>
                        <td>
                            <form action=\"categorie_creator.php\" method=\"post\">
                                <table cellpadding=\"0\" cellspacing=\"0\" style=\"border: 0px;\">
                                <tr>
                                    <td>
                                            <input type=\"hidden\" value=\"NO\" name=\"ShowAsNewTopCategory\" />
                                            <input type=\"hidden\" value=\"".$roll_menu."\" name=\"roll_menu\" />
                                            <input type=\"text\" value=\"".CC_NAZOV."\" name=\"Top_Menu_Caption\" 
                                                    style=\"width:115px;background-color:white;border:1px solid black;\" />
                                    </td>
                                    <td>
                                        <input type=\"submit\" value=\"".CC_OK."\" style=\"width :50px;border:1px solid black;\"
                                            onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\"
                                            onmouseout= \"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />
                                    </td>
                                </tr>
                                </table>
                            </form>
                        </td>
                        <td>
                            <form action=\"categorie_creator.php\" method=\"post\">
                                <input type=\"hidden\" value=\"NO\" name=\"ShowAsNewTopCategory\" />
                                <input type=\"hidden\" value=\"".$roll_menu."\" name=\"roll_menu\" />
                                <input type=\"submit\" value=\"".CC_ZRUSIT."\" style=\"width :50px;border:1px solid black;\"
                                    onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\"
                                    onmouseout= \"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />
                            </form>
                        </td>
                    </tr>
            </table>";		
        }
	else
            print "
                <form action=\"categorie_creator.php\" method=\"post\">
                    <input type=\"hidden\" value=\"".$sql_array_SMnu->ID."\" name=\"ID\" />
                    <input type=\"hidden\" value=\"YES\" name=\"ShowAsNewTopCategory\" />
                    <input type=\"hidden\" value=\"".$roll_menu."\" name=\"roll_menu\" />
                    <input type=\"submit\" value=\"".CPC_PRIDAT_SPOSOB_DOPRAVY."\" style=\"width :310px;border:1px solid black;\"
                        onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\"
                        onmouseout= \"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />
                </form>";
}

function Rename_Topmenu_Form($ShowAsTopMenuUpdate,$ActualID,$roll_menu){
	if($ShowAsTopMenuUpdate==$ActualID){
        $Caption='';
        GetTopmenuInfo($ActualID, $Caption);
		print "
			<table cellpadding=\"0\" cellspacing=\"0\" style=\"border: 0px;\">
			<tr>
                            <td>
                                <form action=\"categorie_creator.php\" method=\"post\">
                                    <table cellpadding=\"0\" cellspacing=\"0\" style=\"border: 0px;\">
                                        <tr style=\"border: 0px; font-size:10px; font-family:verdana;\">
                                            <td>
                                                <input type=\"hidden\" value=\"NO\" name=\"ShowAsTopMenuUpdate\" />
                                                <input type=\"hidden\" value=\"".$roll_menu."\" name=\"roll_menu\" />
                                                <input type=\"hidden\" value=\"".$ActualID."\" name=\"Rename_Topbmenu_ID\" />
                                                <input type=\"text\" value=\"".$Caption."\" name=\"Topmenu_New_Caption\" 
                                                    style=\"width:115px;background-color:white;border:1px solid black;\" />
                                            </td>
                                            <td>
                                              <input type=\"submit\" value=\"".CC_OK."\" style=\"width :50px;border:1px solid black;\"
                                                    onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\"
                                                    onmouseout= \"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />
                                            </td>
                                        </tr>
                                    </table>
                                </form>
                            </td>
                            <td>
                                <form action=\"categorie_creator.php\" method=\"post\">
                                    <input type=\"hidden\" value=\"NO\" name=\"ShowAsTopMenuUpdate\" />
                                    <input type=\"hidden\" value=\"".$roll_menu."\" name=\"roll_menu\" />
                                    <input type=\"submit\" value=\"".CC_ZRUSIT."\" style=\"width :50px;border:1px solid black;\"
                                        onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\"
                                        onmouseout= \"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />
                                </form>
                            </td>
			</tr>
			</table>";	
        }
	else
		print "
			<form action=\"categorie_creator.php\" method=\"post\">
				<input type=\"hidden\" value=\"".$sql_array_TMnu->ID."\" name=\"ID\" />
				<input type=\"hidden\" value=\"$ActualID\" name=\"ShowAsTopMenuUpdate\" />
				<input type=\"hidden\" value=\"".$roll_menu."\" name=\"roll_menu\" />
                                <input type=\"submit\" value=\"".CC_PREMENOVAT."\" style=\"width :310px;border:1px solid black;text-align:center;\"
                                    onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\"
                                    onmouseout= \"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />
			</form>";
}

function Delete_Topmenu_Form($ShowAsTopMenuDelete,$ActualID,$roll_menu){
	if($ShowAsTopMenuDelete==$ActualID)
		print "
			<table cellpadding=\"0\" cellspacing=\"0\" style=\"border: 0px;\">
			<tr>
				<td>
					<form action=\"categorie_creator.php\" method=\"post\">
						<table cellpadding=\"0\" cellspacing=\"0\" style=\"border: 0px;\">
							<tr>
								<td>
									<font style=\"font-size:10px;font-family:verdana;\"><b>".CC_NAOZAJ_ODSTRANIT."</b></font><br />
								</td>
								<td>
									<input type=\"hidden\" value=\"NO\" name=\"ShowAsTopMenuDelete\" />
								</td>
								<td>
									<input type=\"hidden\" value=\"".$roll_menu."\" name=\"roll_menu\" />
									<input type=\"hidden\" value=\"".$ActualID."\" name=\"Delete_Topmenu_ID\" />
							    	<input type=\"submit\" value=\"".CC_ANO."\" style=\"width :50px;border:1px solid black;\"
							        	onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\"
							        	onmouseout= \"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />
							    </td>
							</tr>
						</table>
					</form>
				</td>
				<td>
					<form action=\"categorie_creator.php\" method=\"post\">
						<input type=\"hidden\" value=\"NO\" name=\"ShowAsTopMenuDelete\" />
						<input type=\"hidden\" value=\"".$roll_menu."\" name=\"roll_menu\" />
				    	<input type=\"submit\" value=\"".CC_NIE."\" style=\"width :50px;border:1px solid black;\"
				        	onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\"
				        	onmouseout= \"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />
					</form>
				</td>
			</tr>
		</table>";		
	else
		print "
			<form action=\"categorie_creator.php\" method=\"post\">
				<input type=\"hidden\" value=\"".$sql_array_TMnu->ID."\" name=\"ID\" />
				<input type=\"hidden\" value=\"$ActualID\" name=\"ShowAsTopMenuDelete\" />
				<input type=\"hidden\" value=\"".$roll_menu."\" name=\"roll_menu\" />
		    	<input type=\"submit\" value=\"".CC_ODSTRANIT."\" style=\"width :210px;border:1px solid black;text-align:center;\"
		        	onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\"
		        	onmouseout= \"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />
			</form>";
}
?>